exports.getApplicationList = function(req,res){

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    var appData = [];

    //获取用户应用
    function getUserApplication(cb){

        R.SEND_HTTP(
            req,
            res,
            {
                url    : CORE_APIConfig.coreAPI.easydCloudMemberApplicationSearch.Request_Api_Url + "/cma_uid/"+restfulParams.userid+"/skip/0/limit/999/cma_is_delete/0/sort_order/cma_id-desc",  
                method : 'POST',
                data   : {
                    fields : 'cma_id,cma_name,cma_app_key,cma_apid'
                }
            },
            function (data) {

                appData = data.result.data;
                
                cb();

            }
        )

    }

    //检查应用当前的状态
    function getApplicationStatus(cb){

        F.SerialEach(appData,function(item,index,callback){

            //初始化状态
            item.serverStatus = 0;

            //查询原子层状态
            function searchAtomicStatus(eachCb){
                var containerName = item.cma_app_key + "_atomic";
                R.Ssh_exec_dockerCommand(`${DockerSH.GetContainerStatus} ${containerName}`,function(rs){
                    if(rs.indexOf('running') != -1){
                        eachCb();
                    }else{
                        return callback();
                    }
                    
                })
            }
            //查询聚合层状态
            function searchAggregationStatus(eachCb){
                var containerName = item.cma_app_key + "_aggregation";
                R.Ssh_exec_dockerCommand(`${DockerSH.GetContainerStatus} ${containerName}`,function(rs){
                    if(rs.indexOf('running') != -1){
                        eachCb();
                    }else{
                        return callback();
                    }
                    
                })
            }
            //查询管理层状态
            function searchManagerStatus(eachCb){
                var containerName = item.cma_app_key + "_manager";
                R.Ssh_exec_dockerCommand(`${DockerSH.GetContainerStatus} ${containerName}`,function(rs){
                    if(rs.indexOf('running') != -1){
                        eachCb();
                    }else{
                        return callback();
                    }
                    
                })
            }

            F.Serial([
                searchAtomicStatus,
                searchAggregationStatus,
                searchManagerStatus
            ],() => {
                //全部返回运行中则表明该应用处于运行状态
                item.serverStatus = 1
                callback();
            })

        },cb)

    }

    F.Serial([
        getUserApplication,
        getApplicationStatus
    ],() => {
        RES.successResponse(res,appData);
    })
}